package characterstream;

import java.io.*;

public class BufferedWriterWRSourceFileDemo {

    public static void main(String[] args) {
        BufferedReader bin = null;
        BufferedWriter bout = null;
        File srcFile = new File("D:" + File.separator + "MyUtils.java");
        File destFile = new File("E:" + File.separator + "MyUtils.java");
        try {
            bin = new BufferedReader(new FileReader(srcFile));
            bout = new BufferedWriter(new FileWriter(destFile));
            long startTime = System.currentTimeMillis();
            String s = null;
            while ((s = bin.readLine()) != null) { //一次读出一行字符串
                bout.write(s + "\r\n"); //一次写入一行，后面手工拼上行号回车转义字符。
                //或者使用bout.newLine();
            }

            long endTime = System.currentTimeMillis();
            System.out.println("总用时：" + (endTime - startTime) + "毫秒");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (bin != null) {
                    bin.close();
                    bin = null;
                }
                if (bout != null) {
                    bout.close();
                    bout = null;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
